define(function(require, exports, module) {
  'use strict';

  var Gallery = require('../../common/gallery/gallery');
  var io = require('../../common/io');

  var Form = require('./form');

  new Gallery({
    url: 'coverList',
    delUrl: 'coverUpdateStatus',
    formCfg: {
      buttons: [{
        colspan: null,
        'class': 'pull-right',
        value: '<i class="fa fa-plus"></i> 添加封面',
        attrs: {
          type: 'button',
          'class': 'btn btn-default btn-info',
          'data-role': 'add'
        }
      }]
    },
    buttons: [
      {
        'class': 'btn-info',
        'role': 'edit',
        text: '修改'
      }, {
        text: '删除',
        'role': 'del'
      }
    ],
    key: {
      id: 'docId',
      title: 'docSubject'
    },
    delegates: {
      'click [data-role=add]': function() {
        var self = this;
        new Form({
          title: '添加封面',
          events: {
            success: function(e, data) {
              self.refresh();
            }
          }
        });
      },
      'click [data-role=edit]': function(e) {
        var self = this;
        var id = e.currentTarget.dataset.id;

        io.get('coverView', {docId: id}, function() {
          new Form({
            isEdit: true,
            title: '修改封面',
            coverData: this.data,
            docId: id,
            events: {
              success: function(e, data) {
                self.refresh();
              }
            }
          });
        });

      }
    }
  });
});
